package org.ifi.xechecs.board;


public class Position {
	private byte row;
	private byte col;
	
	public Position(String sMove){
		row = (byte)(sMove.charAt(1) - '1');
        col = (byte)(sMove.charAt(0) - 'a');
	}
	
	public Position(byte p){
		row = (byte) (p/Board.LENGTH);
		col = (byte) (p%Board.LENGTH);
	}

	public Position(byte r, byte c){
		row = r;
		col = c;
	}
	
	public static Position getPosition(String sMove) {
		//implement get position from string
		return new Position(sMove);
	}
	
	public boolean equalPosition(String sPosition){
		if(row == (byte)(sPosition.charAt(1) - '1') && col == (byte)(sPosition.charAt(0) - 'a')){ 
			return true;
		}
		return false;
	}
	
	public byte getRow() {
		return row;
	}

	public void setRow(byte row) {
		this.row = row;
	}

	public byte getCol() {
		return col;
	}

	public void setCol(byte col) {
		this.col = col;
	}

	@Override
	public String toString(){
        String s = "";
        s += (char) ('a' + col);
        s += (char) ('1' + row);
        return s;
	}
	
	public byte toByte(){
		return (byte)(row*Board.LENGTH + col);
	}
}
